﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SYSoft.Model;
using SYSoft.Model.Model.Models;
using SYSoft.Services.SystemManage;

namespace SYSoft.Controllers.SystemManage
{

    public class RoleController : BaseController
    {

        private IRoleServices roleServices;
        readonly IUserRoleServices userRoleServices;
        readonly IMenuRoleServices menuRoleServices;
        public RoleController(IRoleServices roleServices, IUserRoleServices userRoleServices, IMenuRoleServices menuRoleServices)
        {
            this.roleServices = roleServices;
            this.userRoleServices = userRoleServices;
            this.menuRoleServices = menuRoleServices;
        }

        /// <summary>
        /// 获取所有角色
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<MessageModel<PageModel<sys_Role>>> GetAllRole(int pageIndex = 1, int pageSize = 50)
        {
            var res = await roleServices.QueryPage(null, pageIndex, pageSize);
            return MessageModel.CreateSuccessResult(res);
        }



        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<MessageModel<int>> Post([FromBody] sys_Role role)
        {
            //sysUserInfo.uRemark = _user.Name;
            int res = await roleServices.Add(role);
            if (res > 0)
                return MessageModel.CreateSuccessResult<int>(res);
            return MessageModel.CreateFailedResult<int>("添加失败");
        }


        /// <summary>
        /// 修改角色信息
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<MessageModel> Put([FromBody] sys_Role role)
        {
            //sysUserInfo.uRemark = _user.Name;
            var res = await roleServices.Update(role);
            if (res)
                return MessageModel.CreateSuccessResult();
            return MessageModel.CreateFailedResult<int>("添加失败");
        }


        ///// <summary>
        ///// 删除角色信息
        ///// </summary>
        ///// <param name="roleid"></param>
        ///// <returns></returns>
        //[HttpDelete]
        //public async Task<MessageModel> Delete(int roleid)
        //{
        //    var res = await roleServices.DeleteById(roleid);
        //    if (res)
        //    {
        //        // 删除用户角色表
        //        await userRoleServices.Delete()
        //    }
        //        return MessageModel.CreateSuccessResult();
        //    return MessageModel.CreateFailedResult<int>("添加失败");
        //}

    }
}
